//
//  YZMDelayCharge.m
//  YZMicroStock
//
//  Created by apple on 17/7/25.
//  Copyright © 2017年 cqjr. All rights reserved.
//

#import "YZMDelayCharge.h"
#import "YZMAlertView.h"
#import "YZClient.h"

@interface YZMDelayCharge ()

@property (nonatomic, assign) NSTimeInterval severTime;

@end
@implementation YZMDelayCharge


//判断时间是不是下午2：30 - 2：50 之间
+ (BOOL)isTimePeriod{
    NSDate *date = [NSDate date];
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSCalendarUnit unit = NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
    NSDateComponents *dateCompons = [calendar components:unit fromDate:date];
    NSInteger hour = dateCompons.hour;
    NSInteger minute = dateCompons.minute;
    NSInteger seconds = dateCompons.second;
    NSInteger totalSeconds = (hour * 60 + minute) * 60 + seconds;
    NSInteger startSeconds = (14 * 60 + 30) * 60;
#ifndef __OPTIMIZE__
     startSeconds = (14 * 60) * 60;
#endif
    NSInteger endSeconds = (14 * 60 + 50) * 60;
    if (startSeconds <= totalSeconds && totalSeconds <= endSeconds) {
        return YES;
    }
    return NO;
}

// 递延费提示
+ (void)showDelayChargeViewWithConfirmHandle:(BOOL(^)())confirmHandle cancleHandle:(void(^)()) cancleHandle noWaitPayHandle:(void (^)())noWaitPayHandle{
//    if ([self isTimePeriod]) {
        [self requestWaitPayWithConfirmHandle:confirmHandle cancleHandle:cancleHandle noWaitPayHandle:noWaitPayHandle];
//    }else{
//        if (noWaitPayHandle) {
//            noWaitPayHandle();
//        }
//    }
}


+ (void)requestWaitPayWithConfirmHandle:(BOOL(^)())confirmHandle cancleHandle:(void(^)()) cancleHandle noWaitPayHandle:(void (^)())noWaitPayHandle{
    WS(weakSelf);
    [MBProgressHUD showLoadingWithMsg:@""];
    [YZClient getWaitPayWithSuccess:^(NSURLSessionDataTask *task, id responseObject) {
        YZGeneralResultModel *resultModel = responseObject;
        [MBProgressHUD hiddenLoading];
        if (resultModel.success) {
            if ([resultModel.data floatValue] > 0) {
                [weakSelf showAlertViewWithConfirmHandle:confirmHandle cancleHandle:cancleHandle];
            }else{
                if (noWaitPayHandle) {
                    noWaitPayHandle();
                }
            }
        }else{
            [resultModel showMessage];
        }
    } falilure:^(NSError *error) {
        [MBProgressHUD hiddenLoading];
        [error yz_showMessage];
    }];
}

+ (void)showAlertViewWithConfirmHandle:(BOOL(^)())confirmHandle cancleHandle:(void(^)()) cancleHandle{
    YZMAlertView *altertView = [YZMAlertView alertViewForRecommandWithContent:@"温馨提示：请您确认是否已经将今日递延费留在余额中等待扣款，如果继续操作可能会造成操盘中策略因递延费不足被平仓"];
    altertView.cancelButton.hidden = NO;
    [altertView.sureButton setTitle:@"确认" forState:UIControlStateNormal];
    UIWindow *wd = [UIApplication sharedApplication].keyWindow;
    altertView.confirmHandle = confirmHandle;
    altertView.cancleHandle = cancleHandle;
    [altertView showInView:wd];
}


@end
